package com.zxy.demo.guava;

import com.google.common.base.Function;
import com.google.common.base.Optional;
import com.google.common.collect.ImmutableMultiset;
import com.google.common.collect.Lists;

import java.util.List;

/**
 * TransformDemo
 *
 * Created by zxybird on 17/2/9.
 */
public class TransformDemo {

  public static void main(String[] args) {
    Optional<ImmutableMultiset<String>> optional = Optional.fromNullable(testTransform());

    if (optional.isPresent()) {
      for (String p : optional.get()) {
        System.out.println("名字：" + p);
      }
    }

    System.out.println(optional.isPresent());
  }

  public static ImmutableMultiset<String> testTransform() {
    List<Person> personList = Lists.newArrayList(new Person(1, 1, "a", "46546", 1, 20),
        new Person(2, 1, "ab", "46546", 0, 30), new Person(3, 1, "abc", "46546", 0, 25),
        new Person(4, 1, "aef", "46546", 1, 50), new Person(5, 1, "ade", "46546", 0, 27),
        new Person(6, 1, "acc", "46546", 1, 29), new Person(7, 1, "add", "46546", 0, 33));

    return ImmutableMultiset.copyOf(Lists.transform(personList, new Function<Person, String>() {
      @Override
      public String apply(Person input) {
        return input.getName();
      }
    }));
  }

}
